package com.it.controller;

import com.it.exception.BusinessException;
import com.it.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 拦截异常到表现层
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SystemException.class)//拦截系统异常
    public Result doSystemException(SystemException exception){
            //记录日志
            //发送消息运维和开发人员
        return new Result(exception.getCode(),null,exception.getMessage());

    }

    @ExceptionHandler(BusinessException.class)//拦截业务异常
    public Result doBusinessException(BusinessException exception){
        //记录日志
        //发送消息运维和开发人员
        return new Result(exception.getCode(),null,exception.getMessage());

    }

    @ExceptionHandler(Exception.class)//拦截其他异常
    public Result doBusinessException(Exception exception){
        //记录日志
        //发送消息运维和开发人员
        return new Result(Code.SYSTEM_UNKNOW_ERR,null,"系统繁忙，请稍后再试！");

    }
}
